<?php
namespace app\api\model;
use think\Db;
use think\Request;
use think\Controller;
use app\api\common\Common;

class UserModel extends Common
{
	public function register($username, $userpwd, $phone, $regTime){//注册模块
        $db = Db::name('user_info');
        $result = $db->insert([
            'username' => $username,
            'userpwd' => $userpwd,
            'phone' => $phone,
            'reg_time' => $regTime
        ]);
        if($result>0){
        	$this->Json("200", $username, '',"注册成功");
        }else{
            $this->Json("0", $result, '',"注册失败");
        }
    }
    public function getUserByName($username){
        $result = Db::table("user_info")
        ->where("username",$username)
        ->field("id,username")
        ->select();
        //直接返回查询结果
        return $result;
    }
    public function login($username, $userpwd){//登录模块
        $result = Db::table("user_info")
            ->where('username',$userName)
            ->where('userpwd',$userpwd)
            ->find();
            // print_r($result);
        if ($result>0) {
          	//登录成功写入session
            Session::set('admin_id', $userinfo['id']);
            Session::set('admin_name', $userinfo['admin_name']);
            echo $this->Json("200", $username,'',"登录成功");
        } else {
            echo $this->Json("0", "", '',"用户名或密码错误!");
        }
    }
}